package com.myproject.mall.goods.controller;

import com.myproject.mall.common.result.HttpResult;
import com.myproject.mall.domain.dto.OrderForm;
import com.myproject.mall.goods.service.IOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "订单接口")
@Slf4j
@RestController
@RequestMapping("/api/order")
@RequiredArgsConstructor
public class OrderController {
    private final IOrderService orderService;

    @Operation(summary = "创建订单")
    @RequestMapping("/create")
    public HttpResult<OrderForm> createOrder(@RequestBody OrderForm order) {
        return HttpResult.success(orderService.createOrder(order));
    }

    @Operation(summary = "支付订单")
    @RequestMapping("/pay/{orderId}")
    public HttpResult<String> payOrder(@PathVariable String orderId) {
        orderService.payOrder(orderId);
        return HttpResult.success("支付成功");
    }

    @Operation(summary = "取消订单")
    @RequestMapping("/cancel/{orderId}")
    public HttpResult<String> cancelOrder(@PathVariable String orderId) {
        orderService.cancelOrder(orderId);
        return HttpResult.success("取消成功");
    }

    @Operation(summary = "根据状态查询订单")
    @RequestMapping("/get/status/{status}")
    public HttpResult<List<OrderForm>> getOrderByStatus(@PathVariable String status) {
        return HttpResult.success(orderService.getOrderByStatus(status));
    }

    @Operation(summary = "查看销售订单")
    @RequestMapping("/get/sale/{status}")
    public HttpResult<List<OrderForm>> getSaleOrder(@PathVariable String status) {
        return HttpResult.success(orderService.getSaleOrder(status));
    }
}
